package com.prb.json;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.List;
import java.util.Map;

public class TestJackson {


    public static void main(String[] args) throws IOException {


       /* ObjectMapper om = new ObjectMapper();
        Type type = User.class;

        User user = om.readValue("{\"name\":\"prbqb\" , \"age\": \"xixi\"}", (Class<User>)type);
        System.out.println(user);*/


       // File file = new File("");
        //System.out.println(file.getAbsolutePath());



        //URL resourceAsStream = TestJackson.class.getClassLoader().getResource("user.txt");


       // User user = om.readValue(resourceAsStream, User.class);

        //System.out.println(user);


        /**
         * {"1": {"name": "cy","age": "12"},"2": {"name": "prb","age": "14"}
         */
        //{"host":"smtp.qq.com","port":"25","email":"apl0951@aplun.net","password":"llwtzsahhvrnfdhg","encode":"utf-8","protocol":"smtp","auth":"bill","name":"","type":"","notNull":"","title":""}
        String val = "{\"host\":\"smtp.qq.com\",\"port\":\"25\",\"email\":\"apl0951@aplun.net\",\"password\":\"llwtzsahhvrnfdhg\",\"encode\":\"utf-8\",\"protocol\":\"smtp\",\"auth\":\"bill\",\"name\":\"\",\"type\":\"\",\"notNull\":\"\",\"title\":\"\"}";

ObjectMapper om = new ObjectMapper();
        //InputStream resourceAsStream = TestJackson.class.getClassLoader().getResourceAsStream("user.txt");

        EmailConfigBo emailConfigBo = om.readValue(val , EmailConfigBo.class);

        System.out.println(emailConfigBo);


    }

}



class User {


    String name;

    String age;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age='" + age + '\'' +
                '}';
    }
}

class EmailConfigBo implements Serializable {

    //主机
    private String host;

    private String type;

    private String notNull;

    private String title;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getNotNull() {
        return notNull;
    }

    public void setNotNull(String notNull) {
        this.notNull = notNull;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    //端口
    private Integer port;

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    //用户邮箱
    private String email;

    //密码
    private String password;

    //编码
    private String encode;

    private String auth;

    //协议
    private String protocol;

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEncode() {
        return encode;
    }

    public void setEncode(String encode) {
        this.encode = encode;
    }

    public String getProtocol() {
        return protocol;
    }

    public String getAuth() {
        return auth;
    }

    public void setAuth(String auth) {
        this.auth = auth;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    @Override
    public String toString() {
        return "EmailConfigBo{" +
                "host='" + host + '\'' +
                ", port=" + port +
                ", email='" + email + '\'' +
                ", password='" + password + '\'' +
                ", encode='" + encode + '\'' +
                ", protocol='" + protocol + '\'' +
                '}';
    }
}
